package cn.neusoft.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;
import java.util.UUID;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Task {
    private String task_id;

    private String order_id;

    private Integer task_type;

    private Integer task_state;

    private String customer_id;

    private String customer_name;

    private String customer_tel;

    private Long substation_id;

    private String substation_name;

    private String substation_addr;

    private String substation_tel;

    private Long warehouse_id;

    private String warehouse_name;

    private String operator_id;

    private String operator_name;

    private String commodity_id;

    private String commodity_name;

    private BigDecimal price;   // 单价

    private Long amount;    // 数量

    private BigDecimal delivery_fee;    // 配送费

    private BigDecimal total_price;

    private Integer order_kind;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date receive_date;

    private String receive_addr;

    private String memo;    // 送货备注

    private String remark;  // 客户反馈

    private String del_flag;

    private String create_by;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date create_time;

    private String update_by;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date update_time;


    public void calTotalPrice(){
        BigDecimal amountBigDecimal = BigDecimal.valueOf(this.amount);

        if(Objects.equals(this.task_type, 1)){  // 送货
            // 客户应缴总价 = 单价*数量+配送费
            this.total_price = this.price.multiply(amountBigDecimal).add(this.delivery_fee);

        } else if (Objects.equals(this.task_type, 2)) { // 退货
            // 应退额 = 单价*退货数量-配送费
            this.total_price = this.price.multiply(amountBigDecimal).subtract(this.delivery_fee);

        } else if (Objects.equals(this.task_type, 3)) { // 换货
            // 客户应缴总价 = 配送费
            this.total_price = this.delivery_fee;

        }


    }
}